package org.outlook.crawler.util;

import org.outlook.crawler.client.domain.Source;
import org.outlook.crawler.client.pojo.HttpStatus;
import org.outlook.crawler.client.pojo.Webinfo;
import org.outlook.crawler.task.CrawlTask;
import org.outlook.crawler.task.TaskFactory;
import org.outlook.crawler.task.TaskStatus;


public class CrawlerUtil {
	
	private TaskFactory taskFactory;

	public void crawl(CrawlTask task) {
		if(task == null) return ;
		Source resource = task.getSource();
		if(null == resource) {
			//TODO
		}
		
		//update task status
		taskFactory.updateTaskStatus(task, TaskStatus.DOING);
		
		//get real URL for fetching
		String requestURL = getRequestURL(task);
		
		Fetcher fetcher = new Fetcher();
		Webinfo webinfo = fetcher.fetch(requestURL, resource);
		if(null == webinfo) {
			//TODO
		} else if(webinfo.getStatus() == HttpStatus.SC_OK) {
			//TODO
			
			taskFactory.updateTaskStatus(task, TaskStatus.DONE);
		} else if(webinfo.getStatus() != HttpStatus.SC_OK) {
			//TODO
		}
	}

	private String getRequestURL(CrawlTask task) {
		// TODO Auto-generated method stub
		return null;
	}

}
